<?php
namespace app\common\model\signreport;

use think\Model;

class Report extends Model
{
    protected $table = 'reports';
    protected $pk    = 'Id';

    public function getReportTimeAttr($value)
    {
        return Date('Y-m-d', $value);
    }


    // 查询当月日报列表
    public function getMonthReportList($where){
        $data = $this->where($where)->order('ReportTime asc')->select();
        return $data;
    }
    // 查询日报列表
    public function getReportList($where)
    {
        $reportList = $this->where($where)->order('ReportTime asc')->select();
        return $reportList;
    }
    // 查询日报
    public function getReport($Id)
    {
        $report = $this->where('Id', $Id)->find();
        // 日报评价
        $comment = (new Comment())->getList($report['Id']);
        $report['comment'] = $comment;
        return $report;
    }
    // 添加日报
    public function addReport($params)
    {
        $time = time();
        $this->UId = $params['UId'];
        $this->Content = $params['Content'];
        $this->ReportType = isset($params['ReportType'])?$params['ReportType']: 1;
        $this->Imgs = $params['Imgs'];
        $this->ReportTime = $params['ReportTime'];
        $this->CreateTime = $time;
        $this->UpdateTime = $time;
        $this->save();
        return $rst = [
            'Id' => $this->Id,
        ];

    }

    // 更新日报
    public function editReport($params)
    {
        $report = $this::find($params['Id']);
        if ($report === null) {
            return '报告不存在';
        }
        $report->Content = $params['Content'];
        $report->Imgs = $params['Imgs'];
        $report->UpdateTime = time();
        $report->save();
        return $rst = [
            'Id' => $params['Id'],
        ];
    }
}
